<template>
	<view class="container">
		<radio-group name="">
			<view v-for="(item,index) in personInfo" :key='index'>
				<uni-card :title="item.userName" mode="title" :is-shadow="true" :extra="item.userPhone" note="true">
					{{item.userAddress}}
					<template v-slot:footer>
						<view class="footer-style">
							<view style="flex-grow:2">
								<label class="radio" >
									<radio :checked="item.defaultAddress"/><text>默认地址</text>
								</label>
							</view>
							<button type="primary" size="mini" style="margin-right: 20rpx;" @click="edit(item,index)">编辑</button>
							<button type="warn" size="mini">删除</button>
						</view>
					</template>
				</uni-card>
			</view>
		</radio-group>
		<view class="">
			<button type="primary" @click="addAdress()">添加新地址</button>
		</view>
	</view>
	
	
</template>
<script>
	export default {
		data() {
			return {
				personInfo: [{
						userName: '孙笑川',
						userPhone: '18380000000',
						userAddress: '重庆市江北区观音桥好吃街3021号',
						defaultAddress:false
					},
					{
						userName: '卢本伟',
						userPhone: '18380000001',
						userAddress: '重庆市江北区观音桥好吃街3022号',
						defaultAddress:false
					},
					{
						userName: '大司马',
						userPhone: '18380000002',
						userAddress: '重庆市江北区观音桥好吃街3023号',
						defaultAddress:false
					},
					{
						userName: 'Yyf',
						userPhone: '18380000003',
						userAddress: '重庆市江北区观音桥好吃街3024号',
						defaultAddress:false
					},
				]
			}
		},
		methods:{
			addAdress(){
				uni.navigateTo({
					url:'/pages/addMyAddress/addMyAddress'
				})
			},
			edit(item,index){
				console.log(item)
				console.log(index)
			}
		},
		onShow() {
			console.log(1)
			this.pages=getCurrentPages()
			this.currPage = this.pages[this.pages.length - 1]
			console.log(this.currPage.data.newAddressInfo)
			var newInfo={
				userName:this.currPage.data.newAddressInfo.userName,
				userPhone:this.currPage.data.newAddressInfo.userTel,
				userAddress:this.currPage.data.newAddressInfo.area+this.currPage.data.newAddressInfo.address,
				defaultAddress:this.currPage.data.newAddressInfo.defaultAddress
			}
			console.log(newInfo)
			if(this.currPage.data.newAddressInfo.defaultAddress){
				this.personInfo.unshift(newInfo)
			}else{
				this.personInfo.push(newInfo)
			}
		}
		
	}
</script>

<style>
	.container{
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	.footer-style {
		display: flex;
		justify-content: space-around;
	}
</style>
